import requests

# 保存一张图片
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"}
data={
    'name':'xll',
    'age':22
}
response = requests.get("https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/global/img/icons_5859e57.png",headers,params=data)
print(response.content)
with open('1.gif','wb') as f:
    f.write(response.content)
    f.close()
print(response.headers)

print(response.status_code)
print(response.text)
print(response.cookies)
print(response.json())

#文件上传
files = {'file':open('1,gif')}
response = requests.post('http://httpbin.org/post',files=files)
print(response.text)

#获取cookie
response = requests.get("https://www.baidu.com")
print(response.cookies)
for key,value in response.cookies.items():
    print(key+'='+value)

#会话维持
s = requests.Session()
s.get("http://httpbin.org/cookies.set/number/1234563232")
response = s.get("http://httpbin.org/cookies")
print(response.text)

#证书验证
response = requests.get('https://www.12306.cn',verify=False)
print(response.status_code)

response = requests.get('https://www.12306.cn',cert=('/path/server.crt','/path/key'))
print(response.status_code)

#代理设置
proxies = {
    'http':'http://127.0.0.1:9743',
    'https':'https://127.0.0.19743'
}
response.request.get('https://www.taobao.com',proxies=proxies)
print(response.status_code)

